Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create Exercise card #1998

Merged

Conversation

flacial
Copy link
Member

@flacial flacial commented Jun 19, 2022

Related to #1975
Depends on #2001

Merging this PR will create the Exercise card component that will have the following functionalities:

  • Copy user discord username
  • Copy user email
  • Remove exercise flag (unflag)
  • Remove exercise

Image:

image

@vercel
Copy link

vercel bot commented Jun 19, 2022

@flacial is attempting to deploy a commit to the c0d3-prod Team on Vercel.

A member of the Team first needs to authorize it.

@codecov
Copy link

codecov bot commented Jun 19, 2022

Codecov Report

Merging #1998 (f23ec24) into master (32a587e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1998   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          169       170    +1     
  Lines         2903      2937   +34     
  Branches       779       793   +14     
=========================================
+ Hits          2903      2937   +34     
Impacted Files Coverage Δ
...mponents/admin/lessons/AdminLessonExerciseCard.tsx 100.00% <100.00%> (ø)

@vercel
Copy link

vercel bot commented Jun 21, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
c0d3-app ✅ Ready (Inspect) Visit Preview Jun 30, 2022 at 0:50AM (UTC)

}

const Footer = ({ exercise, onRemove }: FooterProps) => {
const [deleteExercise, { loading }] = useMutation(DELETE_EXERCISE)
Copy link
Collaborator

@anthonykhoa anthonykhoa Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a useDeleteExerciseMutation hook you can use from graphql/index file

Copy link
Member Author

@flacial flacial Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too, but it doesn't seem to exist. I'm not certain of the requirements for a resolver to be auto-generated as a hook. The exercise resolvers look exactly as module resolvers

Copy link
Collaborator

@anthonykhoa anthonykhoa Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, its not that codegen gql generates resolvers as a hook, but rather codegen generates us hooks to use in place of useMutation. For these hooks, the functionality should be the same as useMutation, except you don't have to input the query yourself. This also means that if the query contains multiple mutation hitting different resolvers, then all those resolvers will be run.

Example of graphql/index code that inputs query for us(useGetApp):
https://github.com/garageScript/c0d3-app/blob/master/graphql/index.tsx#L2851

I think the problem might be that you haven't made codegen generate a useDeleteExerciseMutation hook yet. Please look into trying to use a useDeleteExerciseMutation hook that codegen gql generates for us.

Copy link
Member Author

@flacial flacial Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem might be that you haven't made codegen generate a useDeleteExerciseMutation hook yet.

So, it seems GraphQL code-gen needs a manually created document such as deleteModule to generate the hook. I'll update it in a different PR. #2006

$answer: String!
$moduleId: Int!
$description: String!
$flaggedAt: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General practice: timestamps should be set on the server side, should not be passed in

Copy link
Contributor

@songz songz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set timestamps on server side

`;

=======
>>>>>>> upstream/master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like an unresolved merge conflict

<>
<button
className={styles['card__section--explanation']}
onClick={() => setShow(!show)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When updating state based on previous value of the state it would be better pass a function the setState to get access to the latest value of the state and prevent hard to find bugs because of race conditions, batching, etc. https://beta.reactjs.org/apis/usestate#updating-state-based-on-the-previous-state

setShow(prevShow => !prevShow) something like this for example.

<span
className={`${styles.card__header__badge} ${styles.card__header__badge__module}`}
>
{toUpper(exercise.module.name)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since this is purely for appearance we shoul consider doing such modifications using the css text-transform property instead of javascript.

const btn = screen.getByText('Show explanation')
await userEvent.click(btn)

expect(screen.getByText('Hide explanation')).toBeTruthy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The following alternatives make the intention of the test more clear and can be considered in the future of the more ambiguous toBeTruthy

expect(btn).toHaveTextContent('Hide Explanation') // Btn's text content has changed
expect(screen.getByText('Hide explanation')).toBeInTheDocument() // An element with the text 'Hide explanation' is in the document

</MockedProvider>
)

expect(screen.queryByText('Show explanation')).toBeFalsy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might to be clearer to test that element does not exist

expect(screen.getByText('Show explanation')).not.toBeInTheDocument()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense. I applied it and the rest of the suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants